package com.zzyl.nursing.controller.member;

import com.zzyl.common.core.domain.AjaxResult;
import com.zzyl.common.core.page.TableDataInfo;
import com.zzyl.nursing.domain.Reservation;
import com.zzyl.nursing.service.IReservationService;
import com.zzyl.nursing.vo.ApointmentVo;
import com.zzyl.nursing.vo.ReservationTimeAndCountVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @Author:zhq
 * @Date: 2025/08/21 21:16
 * @Description:
 */
@RestController
@RequestMapping("/member/reservation")
public class MemberReservationController  {
    @Autowired
    private IReservationService reservationService;

    @GetMapping("cancelled-count")
    public AjaxResult getCancelledCount(){
        Integer count = reservationService. getCancelledCount();
        return AjaxResult.success(count);
    }

    /**
     * 查询时间段剩余预约次数
     * @return
     */
    @GetMapping("/countByTime")
    public AjaxResult getCountByTime(@RequestParam Long time){
        List<ReservationTimeAndCountVo> list = reservationService.getCountByTime(time);
        return AjaxResult.success(list);
    }
    /**
     * 预约
     * @return
     */
    @PostMapping
    public AjaxResult add(@RequestBody ApointmentVo apointmentVo){
        reservationService.add(apointmentVo);
        return AjaxResult.success();
    }

    /**
     * 分页查询预约记录
     * @param pageNum
     * @param pageSize
     * @return
     */
    @GetMapping("/page")
    public AjaxResult getPage(@RequestParam Integer pageNum, @RequestParam Integer pageSize){
        TableDataInfo<Reservation>  table=reservationService.getPage(pageNum,pageSize);
        return AjaxResult.success();
    }

    /**
     * 取消预约
     * @param id
     * @return
     */
    @PutMapping("/{id}/cancel")
    public AjaxResult cancel(@PathVariable Long id){
        reservationService.removeById(id);
        return AjaxResult.success();
    }
}
